package com.ozo.cloud.common.file.config;

import com.ozo.cloud.common.file.constant.FileStoreTypeEnum;
import com.ozo.cloud.common.file.strategy.FileStrategy;
import org.springframework.util.ObjectUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 策略工厂
 *
 * @author qiangesoft
 * @date 2024-05-13
 */
public final class StrategyFactory {

    private static final Map<FileStoreTypeEnum, FileStrategy> STRATEGY_MAP = new ConcurrentHashMap<>();

    /**
     * 通过类型获取策略
     *
     * @param type
     * @return
     */
    public static FileStrategy getStrategy(FileStoreTypeEnum type) {
        return STRATEGY_MAP.get(type);
    }

    /**
     * 注册策略
     *
     * @param type
     * @param strategy
     */
    public static void register(FileStoreTypeEnum type, FileStrategy strategy) {
        if (ObjectUtils.isEmpty(type)) {
            return;
        }
        STRATEGY_MAP.put(type, strategy);
    }
}
